#include "toolbargroupbox.h"
#include <QPainter>
ToolBarGroupBox::ToolBarGroupBox(QWidget *parent)
    : QGroupBox{parent}
{
    this->setMouseTracking(true);
}

void ToolBarGroupBox::paintEvent(QPaintEvent *event)
{
    QRect rect = this->rect();
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing); // 启用抗锯齿，圆角会更平滑

    // 设置画笔为灰色，宽度为2
    QPen pen;
    pen.setColor(Qt::gray);
    pen.setWidth(1);
    painter.setPen(pen);

    painter.setBrush(QColor(240, 240, 240)); //画刷是用来填充背景的

    painter.drawRoundedRect(rect, 10, 10);

    //继续绘制后面的
    //重新设置绘画区域
    pen.setColor(QColor(240, 240, 240));
    painter.setPen(pen);
    QRect rect2 = this->rect();
    rect2.setRect(rect.x() + 10, rect.y(), rect.width() - 10, rect.height());
    painter.drawRect(rect2);
    //把线给绘制上
    pen.setColor(Qt::gray);
    painter.setPen(pen);
    QPoint p1(rect.x() + 10, rect.y());
    QPoint p2(rect.x() + rect.width(), rect.y());
    QPoint p3(rect.x() + 10, rect.y() + rect.height());
    QPoint p4(rect.x() + rect.width(), rect.y() + rect.height());
    painter.drawLine(p1, p2);
    painter.drawLine(p3, p4);
    QWidget::paintEvent(event);
}
